#include <iostream>
#include <vector>
#include <Vector.hpp>

using namespace std;

class Solution
{
public:
    void gameOfLife(vector<vector<int>> &board)
    {
        // 0b00 dd 0b01 ld 0b10 dl 0b11 ll
        for (int x = 0; x < board.size(); x++)
        {
            for (int y = 0; y < board[0].size(); y++)
            {
                int liveNeighbors = 0;
                for (int i = -1; i <= 1; i++)
                {
                    for (int j = -1; j <= 1; j++)
                    {
                        if ((i == 0 && j == 0) || x + i < 0 || x + i >= board.size() || y + j < 0 || y + j >= board[0].size())
                            continue;
                        if (board[x + i][y + j] & 0b01 == 1)
                            liveNeighbors++;
                    }
                }
                cout << liveNeighbors << endl;
                if (board[x][y] == 1)
                {
                    if (liveNeighbors < 2 || liveNeighbors > 3)
                    {
                        board[x][y] = 1;
                    }
                    else
                        board[x][y] = 3;
                }
                else
                {
                    if (liveNeighbors == 3)
                        board[x][y] = 2;
                }
            }
        }
        for (int x = 0; x < board.size(); x++)
        {
            for (int y = 0; y < board[0].size(); y++)
            {
                board[x][y] = board[x][y] >> 1;
            }
        }
    }
};

int main()
{
    cout << "Code289" << endl;
    Solution s;
    vector<vector<int>> board = {{0, 1, 0}, {0, 0, 1}, {1, 1, 1}, {0, 0, 0}};
    s.gameOfLife(board);
    Print2DVector(board);
    return 0;
}